package demo.practice.leetcode_msjd;

public class Msjd0108 {

    public static void main(String[] args) {
        Msjd0108 msjd0108= new Msjd0108();
        msjd0108.setZeroes(new int[][]{{0,0,0,5},{4,3,1,4},{0,1,1,4},{1,2,1,3},{0,0,1,1}});

        /**
         * 0,0,0,5
         * 4,3,1,4
         * 0,1,1,4
         * 1,2,1,3
         * 0,0,1,1
         *
         * x 1,0,1,0,1
         * y 
         */
    }
    public void setZeroes(int[][] matrix) {
        if(matrix.length==0)
            return ;
        int len = matrix.length;
        int len2 = matrix[0].length;
        int[] x = new int[len];
        int[] y = new int[len2];

        for (int i = 0; i < len; i++) {
            if (x[i] == 1)
                continue;
            for (int j = 0; j < len2; j++) {
                if (y[j] == 1)
                    continue;
                if (matrix[i][j] == 0) {
                    x[i] = 1;
                    y[j] = 1;
                }
            }
        }

        for (int i = 0; i < x.length; i++) {

            if (x[i] == 1) {
                for (int j = 0; j < len2; j++) {
                    matrix[i][j] = 0;
                }
            }
        }

        for (int j = 0; j < y.length; j++) {
            if (y[j] == 1) {
                for (int i = 0; i < len; i++) {
                    matrix[i][j] = 0;
                }
            }
        }
    }
}
